package com.edol.painting.main;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.edol.painting.R;

import java.util.List;

/*  =======================================================================================
 *  Copyright (C) 2017 dlboard.com. All rights reserved.
 *
 *  This computer program source code file is protected by copyright law and international
 *  treaties. Unauthorized distribution of source code files, programs, or portion of the
 *  package, may result in severe civil and criminal penalties, and will be prosecuted to
 *  the maximum extent under the law.
 *
 *  ---------------------------------------------------------------------------------------
 * Author:Administrator
 * Date:2017/7/19
 * Desc:
 *
 * ======================================================================================== */
public class LeftDrawerAdapter extends BaseAdapter {
    private Context mContext;
    private String[] mData;

    public LeftDrawerAdapter(Context context, String[] data) {
        mContext = context;
        mData = data;
    }

    @Override
    public int getCount() {
        return mData != null ? mData.length : 0;
    }

    @Override
    public Object getItem(int position) {
        return mData != null ? mData[position] : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder = null;

        if (convertView == null) {
            convertView = initData();
        }

        holder = (Holder)convertView.getTag();
        bindData(holder, position);

        return convertView;
    }

    private View initData() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.layout_left_drawer_item, null);

        Holder holder = new Holder();
        holder.name = (TextView) view.findViewById(R.id.name);
        view.setTag(holder);
        return view;
    }

    private void bindData(Holder holder, int position) {
        holder.name.setText(mData[position]);
    }

    private static class Holder {
        TextView name;
    }
}
